// formPackage/pages/team/performanceRanks/performanceRanks.js
import {
  queryCategoryProductList,//查询销量排行榜
} from "../../../service/jb_product_service"
let app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        topTabIndex: 0,
        themeStyle: "",
        rankThreeList: [
            // {
            //     avatar: "https://images.jiabao19.com/images/public/maintain/2021/12/25/7a6475bba07c47bb98e5db0e0d21c8ebq5sw2kijlc.jpg",
            //     name: "可复美"
            // },
            // {
            //     avatar: "https://images.jiabao19.com/images/public/maintain/2021/12/25/7a6475bba07c47bb98e5db0e0d21c8ebq5sw2kijlc.jpg",
            //     name: "屈臣氏"
            // },
            // {
            //     avatar: "https://images.jiabao19.com/images/public/maintain/2021/12/25/7a6475bba07c47bb98e5db0e0d21c8ebq5sw2kijlc.jpg",
            //     name: "科颜氏"
            // },
        ],
        rankOtherList: [
            // { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 },
            // { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 },
            // { type: 1 }, { type: 1 }, { type: 1 },
        ],
        page: 0,
        pageSize: 50,
        isEmpty: false,
        requestParams: {
          keyword: "",
          priceOrder: '',
          salesOrder: "desc",
          news: 0,
          page: 1,
          limit: 50,
          cid: 0,
          isPartner: true,//是合伙人商品
        },
        otherParams: {
          keyword: "",
          priceOrder: '',
          salesOrder: "",
          salesPriceOrder:"desc",
          news: 0,
          page: 1,
          limit: 50,
          cid: 0,
          isPartner: true,//是合伙人商品
        },

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      //先查询销售额度排行
      this.queryPriceProductList();
    },


    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        if (app.globalData.themeStyle) {
            this.setData({
                themeStyle: app.globalData.themeStyle
            })
        }
    },

    topChangeAction(e) {
        let index = e.currentTarget.dataset.index;
        this.setData({
            topTabIndex: index,
        })
        if(index == 0){
          this.queryPriceProductList();
        }else{
          this.queryCategoryProductList();
        }
    },

    queryCategoryProductList() {
      wx.showLoading();
      queryCategoryProductList(this.data.requestParams).then(res => {
        wx.hideLoading()
        if (res.code == 200) {
          let arr = res.data.list || []
          if (arr.length < 3) {
            this.setData({
              rankThreeList: arr || [],
              rankOtherList: [],
            })
          } else {
            this.setData({
              rankThreeList: arr.slice(0, 3),
              rankOtherList: arr.slice(3)
            })
          }
        }
      }).catch(err => {
        wx.hideLoading()
        wx.showToast({
          title: err || '加载失败',
          icon: "none"
        })
    
      
        console.error("JJLog:queryCategoryProductList", err);
      })
    },

    queryPriceProductList() {
      wx.showLoading();
      queryCategoryProductList(this.data.otherParams).then(res => {
        wx.hideLoading()
        if (res.code == 200) {
          let arr = res.data.list || []
          if (arr.length < 3) {
            this.setData({
              rankThreeList: arr || [],
              rankOtherList: [],
            })
          } else {
            this.setData({
              rankThreeList: arr.slice(0, 3),
              rankOtherList: arr.slice(3)
            })
          }
        }
      }).catch(err => {
        wx.hideLoading()
        wx.showToast({
          title: err || '加载失败',
          icon: "none"
        })
    
      
        console.error("JJLog:queryCategoryProductList", err);
      })
    },

})